{extend name='base' /}
{block name='content' /}
<!--tab标签-->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">编辑站点信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="{:url('admin/setup/update')}" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" value="{$setup.name}" required  lay-verify="required" placeholder="请输入网站名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" value="{$setup.title}" required  lay-verify="required" placeholder="请输入网站标题" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站关键词</label>
                            <div class="layui-input-block">
                                <textarea name="keywords" placeholder="（选填）请输入网站关键词" class="layui-textarea">{$setup.keywords}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站描述</label>
                            <div class="layui-input-block">
                                <textarea name="description" placeholder="（选填）请输入网站描述" class="layui-textarea">{$setup.description}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站图标</label>
                            <div class="layui-input-block">
                                <img id="icosrc" src="{if condition='$setup.ico neq null'}__UPLOAD__/{$setup.ico}{/if}" onerror="this.src='__IMAGES__/wutu.jpg'" style="width:50px;height:50px;margin-right:10px;border-radius:50%">
                                <button type="button" class="layui-btn" id="ico_upload">
                                    <i class="layui-icon">&#xe67c;</i>上传图标（ICO格式）
                                </button>
                                <input type="hidden" name="ico" id="ico" value="{$setup.ico}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">版权信息</label>
                            <div class="layui-input-block">
                                <input type="text" name="copyright" value="{$setup.copyright}" required  lay-verify="required" placeholder="请输入版权信息" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">ICP备案号</label>
                            <div class="layui-input-block">
                                <input type="text" name="icp" value="{$setup.icp}" placeholder="请输入ICP备案号" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">网站风格</label>
                            <div class="layui-input-block">
                                <select name="template" lay-verify="required" lay-search="">
                                    <option value="./themes/index/" {if condition="$setup.template=='./themes/index/'"} selected="selected"{/if}>默认风格</option>
                                    <option value="./themes/index_red/" {if condition="$setup.template=='./themes/index_red/'"} selected="selected"{/if}>红色风格</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">技术支持</label>
                            <div class="layui-input-block">
                                <input type="text" name="technology_name" value="{$setup.technology_name}" placeholder="（选填）请输入技术支持" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">技术电话</label>
                            <div class="layui-input-block">
                                <input type="text" name="technology_tel" value="{$setup.technology_tel}" placeholder="（选填）请输入技术电话" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">技术网址</label>
                            <div class="layui-input-block">
                                <input type="text" name="technology_url" value="{$setup.technology_url}" placeholder="（选填）请输入技术网址" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    layui.use(['form','layer','upload'], function(){
        var form = layui.form,$ = layui.jquery, layer = layui.layer,upload = layui.upload;

        /**
         * 通用表单提交(AJAX方式)
         */
        form.on('submit(*)', function (data) {
            $.ajax({
                url: data.form.action,
                type: data.form.method,
                data: $(data.form).serialize(),
                success: function (info) {
                    if (info.code === 1) {
                        setTimeout(function () {
                            location.href = info.url;
                        }, 1000);
                    }
                    layer.msg(info.msg);
                }
            });

            return false;
        });

        /**
         * 通用ICO上传
         */
        var uploadInst = upload.render({
            elem: "#ico_upload" //绑定元素
            ,url: "{:url('api/upload/ico')}" //上传接口
            ,accept: 'file' //普通文件
            ,exts: 'ico' //只允许上传ico文件
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            ,done: function(res, index, upload){
                layer.closeAll('loading'); //关闭loading
                if (res.error === 0) {
                    $('#icosrc').attr("src","__UPLOAD__/"+res.url);
                    $('#ico').val(res.url);
                } else {
                    layer.msg(res.message);
                }
            }
            ,error: function(index, upload){
                layer.closeAll('loading'); //关闭loading
            }
        });
    });
</script>
{/block}